<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="/Plug-in/ext/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="/Plug-in/ext/resources/css/xtheme-slate.css" />
<script type="text/javascript" charset="utf-8" src="/Plug-in/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" charset="utf-8"  src="/Plug-in/ext/ext-all.js"></script>
<script type="text/javascript">Ext.BLANK_IMAGE_URL = '/Plug-in/ext/resources/images/default/s.gif';</script>
</head>
<style type="text/css">
.x-date-menu > ul{
display: inline;
}
.x-date-menu > ul li{
display: inline;
}
.hang {
	background:#EEEEEF;
	border-top:1px dotted #B5B8C8;
	border-bottom:1px dotted #B5B8C8;
}

body{ height:100%;}

.x-grid3-hd-row TD {
    font-size: 14px;/*改变表头字体大小*/
	font-family:微软雅黑;
}

.x-grid3-row TD {
    font-size: 12px;/*改变行内容字体大小*/
    LINE-HEIGHT: 14px;
	font-family:微软雅黑;
}

</style>
<script>
/*!
 * Ext JS Library 3.3.1
 * Copyright(c) 2006-2010 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */
//获得屏幕的尺寸
function getPageSize(){
   
    var xScroll, yScroll;
   
    if (window.innerHeight && window.scrollMaxY) {   
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
   
    var windowWidth, windowHeight;
    if (self.innerHeight) {    // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }   
   
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){   
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
} 
 
Ext.onReady(function(){

    Ext.QuickTips.init();
    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';
		
	//获取表单配置信息的参数
	var requestParams = {op : 'fy',tid:<{$tree.id}> ,bdtid:'<{$bdtid}>' , bdid :'<{$bdid}>',dbname:'<{$table.tabname}>'}; 
	
	//获取数据库内容
    var data = {url : "./l.php" , method:'POST'};
	
	//这是个神马东东
    var robj = [
			//new Ext.grid.RowNumberer(),//原样写就可以
            {name: 'id'},
			<{section name=li loop=$xr}>
			{name:'<{$xr[li].fname}>'}
			<{if $smarty.section.li.index+1 < $xr|@count}>,<{/if}>
			<{/section}>
        ];
// ds reader
	var rd = new Ext.data.JsonReader({
		totalProperty:'total',
		root:'data',
		id:'jsonreader'
	},robj);


	//数据载入模型
	var ds = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy(data),
		reader:rd,
		baseParams:requestParams,
		sortInfo:{field :'id',direction:'DESC'}
	});
	
	ds.load();
	
	var colModel = new Ext.grid.ColumnModel([
					{id:'id',header:'ID',dataIndex:'id',width:50,sortable:true,readOnly:true},
					<{section name=li loop=$xr}>
						{
							id:'<{$xr[li].id}>',
							header:'<{$xr[li].name}>',
							<{if 1==$xr[li].xr}>hidden:true,<{/if}>
							dataIndex:'<{$xr[li].fname}>',
							width:<{$xr[li].wd}>,
							sortable:true<{if $xr[li].renderer neq ''}><{$config[li].renderer}><{/if}>
						}
					<{if $smarty.section.li.index+1 < $xr|@count}>,<{/if}>
					<{/section}>
	]);

  
	
//删除处理
function delTask(id){
         var prez = [];
         prez.push(id);

		var encoded_array= Ext.encode(prez);

		Ext.Ajax.request({
			waitMsg:'正在操作',
			url:'./l.php',
			method:'POST',
			params:{
				op:'del',
				ids:encoded_array,
				dbname:'<{$table.tabname}>'
			},
			success:function(response){
				    var json = Ext.decode(response.responseText);
					if(json.success){
						Ext.MessageBox.alert('消息',"数据删除成功！");
						gridForm.form.reset();
						ds.reload();
					}
					else{
						Ext.MessageBox.alert('警告',"权限不足!");
					}
			},
			failure:function(response){
				Ext.MessageBox.alert('警告',"无法连接数据库!");
			}

		});
}

	
	var pageSize=getPageSize();
	
	//显示部分，表单+列表	
    var gridForm = new Ext.FormPanel({
        id: 'company-form',
        frame: true,
        labelAlign: 'left',
        title: '<{$tree.title}>',
        width:pageSize[0],
		height:pageSize[1],//屏幕可用工作区高度
        layout: 'border', 
        items: [{
            region:'center',
            width:Math.round(pageSize[0]/5*3),
			split:true,
			minSize:Math.round(pageSize[0]/5*2),
			maxSize:Math.round(pageSize[0]/5*3),
            items: {
                xtype: 'grid',
                ds: ds,
                cm: colModel,
                sm: new Ext.grid.RowSelectionModel({
                    singleSelect: true,
                    listeners: {
						//与表单级联
                        rowselect: function(sm, row, rec) {
                            Ext.getCmp("company-form").getForm().loadRecord(rec);
							gridForm.findById('tid').value=rec.json.id;
                        }
                    }
                }),
                height:pageSize[1]-20,
                border: true,
                listeners: {
                    viewready: function(g) {
                        g.getSelectionModel().selectRow(0);
                    } // Allow rows to be rendered.
                }
            }
        },{
            region:'east',
			width:Math.round(pageSize[0]/5*2),
			minSize:Math.round(pageSize[0]/5*2),
			maxSize:Math.round(pageSize[0]/5*3),
			autoHeight:true,
			split:true,
			buttonAlign:'center',
            bodyStyle: Ext.isIE ? 'padding:0 0 5px 15px;' : 'padding:10px 15px;',
            border: false,
            style: {
                "margin-left": "10px", // when you add custom margin in IE 6...
                "margin-right": Ext.isIE6 ? (Ext.isStrict ? "-10px" : "-13px") : "0" 
            },
            items: [{
						xtype:'hidden',
			            name: 'id',
						id:'id',
			            value:''
		    },{
						xtype:'hidden',
			            name: 'tid',
						id:'tid',
			            value:'<{$tid}>'
		    },
			<{$fcf}>
			],
			buttons:[
		{
			xtype:'button',
            text: '保存',
            handler:function (){				
				if(gridForm.form.isValid()){//如果表单有不允许为空项未填，则不允许提交表单
					gridForm.form.doAction('submit',{
						url:'i.php',
						method:'POST',
						params:{op:'save'},
						waitMsg:'正在提交....',
						success:function(form,action){
							ds.reload();
						},
						//提交失败的回调函数
						failure:function(form,action){
							Ext.MessageBox.alert('警告',"无法连接数据库!");
						}
				});
				}
			}
        },
		{
        	//新建按钮
			xtype:'button',
            text: '新建',
			handler:function (){
				gridForm.findById('tid').value='';
				gridForm.form.reset();	
			}
        },
		{
        	//删除按钮
			xtype:'button',
            text: '删除',
			handler:function (){
				if(''==gridForm.findById('id').value){
					Ext.Msg.alert('提示', '所选内容为空!');
				}
				else {
					Ext.Msg.confirm('操作确认','你确认删除当前选择项目？',function(a){
						if('yes'==a){
							delTask(gridForm.findById('id').value);
						}
					});
				}
			}
        }]
	}],
		
    renderTo: 'body'
   });
});
</script>
<body id="body">
</body>
</html>
